package com.czk.route.receive;

import com.czk.utils.RabbitmqUtils;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/1/2 21:53
 */
@SuppressWarnings("All")
public class ThirdConsumer {
    public static void main(String[] args) throws IOException, TimeoutException {
        // 获取链接对象
        Connection connection = RabbitmqUtils.getCzkConnection();
        Channel channel = connection.createChannel();
        // 绑定交换机
        channel.exchangeDeclare("logs","direct");
        // 临时队列
        String queue = channel.queueDeclare().getQueue();
        // 绑定交换机和队列
        String routing_key="debug";
        channel.queueBind(queue,"logs",routing_key);
        // 消费消息
        channel.basicConsume(queue,true,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者3 "+new String(body));
            }
        });
    }
}
